package madoop.me;


import java.util.Collection;
import java.util.Iterator;

public class Drive
{
    public String           name;
    public DiskSpace        space = new DiskSpace();
    
    public DriveEntry[]     entries;

    
    public Drive(String name, String... paths)
    {
        this.name = name;
        entries = new DriveEntry[paths.length];
        for (int i = 0; i < paths.length; i++)
            entries[i] = new DriveEntry(paths[i]);
    }
    
    
    public Drive(String name, Collection<String> paths)
    {
        this.name = name;
        entries = new DriveEntry[paths.size()];
        Iterator<String>    itr = paths.iterator();
        
        for (int i = 0; i < entries.length; i++)
            entries[i] = new DriveEntry(itr.next());

    }
    
    
    public void refresh()
    {
        space.reset();
        for (DriveEntry entry: entries) {
            space.total += entry.space.total;
            space.free += entry.space.free;
            space.writable += entry.space.writable;
        }
    }
    
    
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append(Drive.class.getSimpleName()).append(':').append(name).append(" {");
        space.toString(sb);
        sb.append("}");
        return sb.toString();
    }
}
